home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / slip / cslip-2.6 / tip / log.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-30  |  2.4 KB  |  98 lines

  1. /*
  2.  * Copyright (c) 1983 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that: (1) source distributions retain this entire copyright
  7.  * notice and comment, and (2) distributions including binaries display
  8.  * the following acknowledgement:  ``This product includes software
  9.  * developed by the University of California, Berkeley and its contributors''
  10.  * in the documentation or other materials provided with the distribution
  11.  * and in all advertising materials mentioning features or use of this
  12.  * software. Neither the name of the University nor the names of its
  13.  * contributors may be used to endorse or promote products derived
  14.  * from this software without specific prior written permission.
  15.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18.  */
  19.  
  20. #ifndef lint
  21. static char sccsid[] = "@(#)log.c    5.3 (Berkeley) 9/2/88";
  22. #endif /* not lint */
  23.  
  24. #include "tip.h"
  25. #include <grp.h>
  26.  
  27. #ifdef ACULOG
  28. static    FILE *flog = NULL;
  29.  
  30. #ifdef PRISTINE
  31. int pristine = 1;    /* so it is easier to change for binary-only sites */
  32. #else
  33. int pristine = 0;
  34. #endif
  35.  
  36. /*
  37.  * Log file maintenance routines
  38.  */
  39.  
  40. logent(group, num, acu, message)
  41.     char *group, *num, *acu, *message;
  42. {
  43.     static int uid = -1, gid = -1;
  44.     static char *user, *ugroup;
  45.     int i;
  46.       long t;
  47.     char *timestamp;
  48.     struct passwd *pwd;
  49.     struct group *grp;
  50.  
  51.     if (flog == NULL)
  52.         return;
  53.     if (flock(fileno(flog), LOCK_EX) < 0) {
  54.         perror("tip: flock");
  55.         return;
  56.     }
  57.     if (uid != (i = geteuid())) {
  58.         uid = i;
  59.         setpwent();
  60.         if ((pwd = getpwuid(getuid())) == NOPWD)
  61.             user = "???";
  62.         else
  63.             user = pwd->pw_name;
  64.     }
  65.     if (gid != (i = getgid())) {
  66.         gid = i;
  67.         setgrent();
  68.         if ((grp = getgrgid(getgid())) == (struct group *)0)
  69.             ugroup = "???";
  70.         else
  71.             ugroup = grp->gr_name;
  72.     }
  73.     t = time(0);
  74.     timestamp = ctime(&t);
  75.     timestamp[24] = '\0';
  76.     fprintf(flog, "%s:%s (%s) <%s, %s, %s> %s\n",
  77.         user, ugroup, timestamp, group,
  78.         pristine ? "" : num,
  79.         acu, message);
  80.     (void) fflush(flog);
  81.     (void) flock(fileno(flog), LOCK_UN);
  82. }
  83.  
  84. loginit()
  85. {
  86.  
  87.       flog = fopen(value(LOG), "a");
  88.     if (flog == NULL) {
  89.         int e = errno;
  90.         fprintf(stderr, "tip: can't open log file: ");
  91.         errno = e;
  92.         perror(value(LOG));
  93.         putc('\r', stderr);
  94.         putc('\n', stderr);
  95.     }
  96. }
  97. #endif
  98.